local db = TUNING.MOD_WEBBER_THE_TRAINER.ITEMS.webbert_bread


---@class components
---@field webbert_bread component_webbert_bread

-- local function on_val(self, value)
    -- self.inst.replica.webbert_bread:SetVal(value)
-- end

---@class component_webbert_bread
---@field inst ent
---@field ate boolean
local webbert_bread = Class(
---@param self component_webbert_bread
---@param inst ent
function(self, inst)
    self.inst = inst
    -- self.val = 0
    self.ate = false
end,
nil,
{
    -- val = on_val,
})

function webbert_bread:OnSave()
    return {
        -- val = self.val
        ate = self.ate,
    }
end

function webbert_bread:OnLoad(data)
    -- self.val = data.val or 0
    self.ate = data.ate or false

    if self.ate then
        self.inst.AnimState:SetBank('webbert_bread_half')
        self.inst.AnimState:SetBuild('webbert_bread_half')

        self.inst.components.inventoryitem:ChangeImageName('webbert_bread_half')
    end
end

---comment
---@param eater ent
---@return boolean
function webbert_bread:Bite(eater)
    -- 如果吃过一口了
    if self.ate then
        self.inst:Remove()
    else
        self.ate = true
        self.inst.AnimState:SetBank('webbert_bread_half')
        self.inst.AnimState:SetBuild('webbert_bread_half')
        self.inst.AnimState:PlayAnimation('idle',true)

        self.inst.components.inventoryitem:ChangeImageName('webbert_bread_half')

        if self.inst.components.named then
            self.inst.components.named:SetName(STRINGS.MOD_WEBBER_THE_TRAINER.ITEMS.webbert_bread.half_name)
        end
    end


    if eater.components.hunger then
        eater.components.hunger:DoDelta(db.delta_hunger)
    end
    if eater.components.sanity then
        eater.components.sanity:DoDelta(db.delta_san)
    end
    if eater.components.health then
        eater.components.health:DoDelta(db.delta_health)
    end
    eater:AddDebuff('buff_webbert_bread_burnrate_buff','buff_webbert_bread_burnrate_buff')

    return true
end

return webbert_bread